package com.huluobo.a2308douyindemo.adapter

import android.animation.ObjectAnimator
import android.util.Log
import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2308douyindemo.R
import com.huluobo.a2308douyindemo.bean.VideoBean
import com.huluobo.a2308douyindemo.utils.ImageUtils
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer

/**
 *  Created by LC on 2025/10/23.
 */
class VideosAdapter : BaseQuickAdapter<VideoBean, BaseViewHolder>(R.layout.item_videos) {
    override fun convert(holder: BaseViewHolder, item: VideoBean) {
        //获取播放器
        val player = holder.getView<StandardGSYVideoPlayer>(R.id.item_videos_player)
        //设置返回按键消失
        player.backButton.visibility = View.GONE
        //设置播放地址,1.播放地址,2.边缓存边播放,3.视频标题
        player.setUp(item.videopath, true, "")

        holder.setText(R.id.item_videos_pao_tv, item.description)
        holder.setText(R.id.item_videos_time_tv, item.ctime)
        holder.setText(R.id.item_videos_desc_tv, item.title)
        holder.setText(R.id.item_videos_name_tv, item.name)


        //加载头像
        ImageUtils.loadCircleImage(context, item.avatar_url, holder.getView(R.id.item_videos_header_iv))

        //如果该字段为true,就证明已点赞
        if (item.isLiked) {
            holder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuanred)
        } else {
            holder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuan)
        }

        //获取右下角音乐播放器
        val musicPlayer = holder.getView<ImageView>(R.id.item_videos_music_player_iv)
        ImageUtils.loadCircleImage(context, item.videomainimag, musicPlayer)

        val animator = ObjectAnimator.ofFloat(musicPlayer, "rotation", 0f, 360f)
        animator.duration = 3000
        animator.repeatCount = -1
        animator.interpolator = LinearInterpolator()
        animator.start()

    }
}